package com.example.adminbase.web;

import com.example.adminbase.dao.SysUserMapper;
import com.example.adminbase.domain.SysUser;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/auth")
public class AuthorizationController {

    private final SysUserMapper sysUserMapper;

    @Autowired
    public AuthorizationController(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }


    @GetMapping("/userInfo")
    public SysUser userInfo() {
        SysUser user = (SysUser) SecurityUtils.getSubject().getSession().getAttribute("user");
        if(user != null) {
            return user;
        }else { //id为空的User代表匿名用户
            return new SysUser();
        }
    }
}
